package org.gnyxy.controller.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gnyxy.result.Result;
import org.gnyxy.service.AddressDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userAddressDic")
@RequestMapping("/front/addressDic")
@Slf4j
@Api(tags = "小程序端-地址字典")
public class AddressDicController {

    @Autowired
    private AddressDicService addressDicService;

    @GetMapping("/getDistrict")
    @ApiOperation("查看地址所有的区县")
    public Result getDistrict(){
        log.info("查看地址所有的区县");
        List<String> districts = addressDicService.getDistrict();
        return Result.success(districts);
    }

    @GetMapping("/getStreet")
    @ApiOperation("根据区县查看所有的乡镇街道")
    public Result getStreet(String districtName){
        log.info("根据区县查看所有的乡镇街道: {}",districtName);
        List<String> streets = addressDicService.getStreet(districtName);
        return Result.success(streets);
    }

    @GetMapping("/getVillage")
    @ApiOperation("根据区县和乡镇街道查看小区、村")
    public Result getVillage(String districtName,String streetName){
        log.info("根据区县:{}和乡镇街道:{}查看小区、村",districtName,streetName);
        List<String> villages = addressDicService.getVillage(districtName,streetName);
        return Result.success(villages);
    }

}
